package com.example.wangzh.developkit.control.hover;

import android.content.Context;

import androidx.annotation.NonNull;
import androidx.core.content.ContextCompat;
import android.view.View;
import android.widget.ImageView;

import com.example.wangzh.developkit.R;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import io.mattcarroll.hover.HoverMenuAdapter;
import io.mattcarroll.hover.NavigatorContent;

/**
 * Created by zhwang16 on 2018/8/30.
 */

public class HoverDemoMenuAdapter implements HoverMenuAdapter {

    private final Context mContext;
    private final List<String> mTabIds;
    private final Map<String, NavigatorContent> mData;
    private final Set<ContentChangeListener> mContentChangeListeners = new HashSet<>();

    public HoverDemoMenuAdapter(@NonNull Context context, @NonNull Map<String, NavigatorContent> data) throws IOException {
        mContext = context;
        mData = data;

        mTabIds = new ArrayList<>();
        for (String tabId : mData.keySet()) {
            mTabIds.add(tabId);
        }
    }

    @Override
    public int getTabCount() {
        return mTabIds.size();
    }

    @Override
    public View getTabView(int index) {
        ImageView imageView = new ImageView(mContext);
        imageView.setBackgroundResource(R.drawable.shape_round_20dp_backcolor);
        switch (index) {
            case 0:
                imageView.setImageResource(R.drawable.cycle);
                break;
            case 1:
                imageView.setImageResource(R.drawable.run);
                break;
            case 2:
                imageView.setImageResource(R.drawable.android);
                break;
            default:
                break;
        }
        imageView.setPadding(10, 10, 10, 10);
        return imageView;
    }

    @Override
    public long getTabId(int position) {
        return position;
    }

    @Override
    public NavigatorContent getNavigatorContent(int index) {
        String tabId = mTabIds.get(index);
        return mData.get(tabId);
    }

    @Override
    public void addContentChangeListener(@NonNull ContentChangeListener listener) {
        mContentChangeListeners.add(listener);
    }

    @Override
    public void removeContentChangeListener(@NonNull ContentChangeListener listener) {
        mContentChangeListeners.remove(listener);
    }
}
